import axios from "axios";

const devUrl: string = "http://127.0.0.1:7001";
/**
 * 封装的axios请求，直接将response全部返回
 * @param method 请求方式，例如post或get
 * @param url 请求地址
 * @param data 请求参数，使用json格式
 */
const request = (method: string, url: string, data?: object) => {
  //使用Promise包装Axios以便异步调用请求
  return new Promise((resolve, reject) => {
    axios({
      method: method,
      url: devUrl + url,
      data: data,
    }).then(res => {
      resolve(res);
    }).catch(err => {
      reject(err);
    });
  });
};

const tRequest = (method: string, url: string, data?: object) => {
  return new Promise((resolve, reject) => {
    axios({
      method: method,
      url: devUrl + url,
      data: data,
    })
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
  });
};
export {
  request, devUrl, tRequest
}